package com.jbookshelf.beans;

import java.io.IOException;

import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("request")
public class LoginBean {
	
	private String login;
	private String password;
	
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	  public void doLogin() throws IOException, ServletException
	    {
	        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
	        RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
	                 .getRequestDispatcher("/j_spring_security_check");
	        dispatcher.forward((ServletRequest) context.getRequest(),
	                (ServletResponse) context.getResponse()); 
	        FacesContext.getCurrentInstance().responseComplete();
	    }
}
